package com.sloan.community.controller;

import com.sloan.community.common.res.Result;
import com.sloan.community.common.vo.FileVO;
import com.sloan.community.common.vo.VideoVo;
import com.sloan.community.service.FileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor_={@Lazy})
@RequestMapping("file")
public class FileController {

    private final FileService fileService;


    @PostMapping("upload")
    public Mono<Result<FileVO>> upload(@RequestPart("file") FilePart filePart) {
       return fileService.upload(filePart);
    }

    @PostMapping("upload/video")
    public Mono<Result<VideoVo>> uploadVideo(@RequestPart("video") FilePart filePart) {
        return fileService.uploadVideo(filePart);
    }
}
